{% extends 'home.html' %}
{% block content %}

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>烘干法水分测定仪校准</title>
    <link href="/static/css/kfc_yb.css" rel="stylesheet">
    </link>
    <script src="/static/bootstrap/js/jquery.min.js" type="text/javascript"></script>
    <script src="/static/js/kfc_yb.js" type="text/javascript"></script>
    <style>
        /* 保留其他样式不变 */
        table#tools input,
        table#tools select {
            width: 95% !important;
        }

        table.table td {
            vertical-align: middle !important;
        }

        /* 固定高度的单元格 */
        table.table td,
        table.table th {
            height: 40px;
        }

        /* 修改：调整第二列选择框宽度 */
        table#tools select[name^="BLPH_Bh"] {
            width: 120px !important;
        }

        /* 新增：专门针对示值误差表格的输入框居中样式 */
        table#table1 input[type="number"],
        table#table1 input[type="text"] {
            display: block;
            margin: 0 auto;
            text-align: center;
            padding: 3px 5px;
            width: 80px;
            box-sizing: border-box;
        }

        /* 保持表格单元格垂直居中 */
        table#table1 td {
            vertical-align: middle;
            text-align: center;
        }
    </style>
</head>

<body onload="disableBackButton();" onpageshow="if (event.persisted) disableBackButton();" class="">
    <script>
        function disableBackButton() {
            window.history.forward();
        }
    </script>
    <form name="form1" method="post" id="form1">
        {% csrf_token %}
        <div class="c-layout-page">
            <div class="c-content-box c-size-md c-bg-white">
                <div class="container">
                    <div class="c-content-title-1">
                        <h3 class="c-center c-font-dark c-font-uppercase">烘干法水分测定仪校准</h3>
                        <div class="c-line-center c-theme-bg"></div>
                        <p class="c-center"></p>
                    </div>
                    <div class="c-content-panel">
                        <div class="c-label">仪器基础信息输入</div>
                        <div class="c-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <table class="table">
                                        <tbody>
                                            <tr>
                                                <th scope="row" style="text-align:center">仪器名称</th>
                                                <td colspan="2"><input name="A1PH_Name01" type="text" value="烘干法水分测定仪"
                                                        id="A1PH_Name01" style="height:25px;width:350px"></td>
                                                <th style="text-align:center">仪器接收编号</th>
                                                <td colspan="2"><input name="A1PH_Received02" type="text"
                                                        value="{{ A1PH_Received02 }}" readonly="readonly"
                                                        id="A1PH_Received02"
                                                        style="background-color:#F3F3F3;height:25px; width:300px">
                                                </td>
                                            </tr>

                                            <tr>
                                                <th scope="row" style="text-align:center">型号/规格</th>
                                                <td><input name="A1PH_ProdModel03" type="text" id="A1PH_ProdModel03"
                                                        style="height:25px;width:240px"></td>
                                                <th style="text-align:center">仪器序列号</th>
                                                <td><input name="A1PH_SN04" type="text" id="A1PH_SN04"
                                                        style="height:25px">
                                                </td>
                                                <th style="text-align:center">环境条件</th>
                                                <td>
                                                    <input name="A1PH_Wd11" type="text" id="A1PH_Wd11"
                                                        style="height:25px; width:50px"
                                                        onblur="formatToOneDecimal(this)">&nbsp;°C &nbsp;&nbsp;
                                                    <input name="A1PH_Sd12" type="text" id="A1PH_Sd12"
                                                        style="height:25px; width:50px"
                                                        onblur="formatToOneDecimal(this)">&nbsp;%RH
                                                    <script>
                                                        function formatToOneDecimal(inputElement) {
                                                            if (inputElement.value !== '') {
                                                                const value = parseFloat(inputElement.value);
                                                                if (!isNaN(value)) {
                                                                    inputElement.value = value.toFixed(1);
                                                                }
                                                            }
                                                        }

                                                        // 页面加载时也格式化已有的值
                                                        document.addEventListener('DOMContentLoaded', function () {
                                                            formatToOneDecimal(document.getElementById('A1PH_Wd11'));
                                                            formatToOneDecimal(document.getElementById('A1PH_Sd12'));
                                                        });
                                                    </script>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th style="text-align:center" scope="row">校准依据</th>
                                                <td colspan="3"><input name="A1PH_Xz06" type="text"
                                                        value="JJG 658-2022烘干法水分测定仪检定规程" id="A1PH_Xz06"
                                                        style="height:25px;width:420px"></td>
                                                <th style="text-align:center">校准日期</th>
                                                <td><input name="A1PH_Rq07" type="text" value="{{ date }}"
                                                        id="A1PH_Rq07" style="height:25px"></td>
                                            </tr>

                                            <tr>
                                                <th style="text-align:center" scope="row">最大称量</th>
                                                <td colspan="3"><input name="A1PH_maxweigh" type="text"
                                                        id="A1PH_maxweigh" style="height:25px;width:420px"></td>
                                                <th style="text-align:center">实际分度值(d)</th>
                                                <td><select name="A1PH_d" type="text" id="A1PH_d" style="height:25px">
                                                        <option value="0.001">0.001</option>
                                                        <option value="0.0001">0.0001</option>
                                                </td>
                                            </tr>

                                            <tr>
                                                <td colspan="6"
                                                    style="height:20px;text-align:center;background-color:aliceblue">
                                                    标准器及配套设备
                                                </td>
                                            </tr>

                                            <tr>
                                                <td colspan="6">
                                                    <table class="table" id="tools">
                                                        <tbody>
                                                            <tr>

                                                                <th style="text-align:center">名称/型号</th>
                                                                <th style="text-align:center">编号</th>
                                                                <th style="text-align:center">测量范围</th>
                                                                <th style="text-align:center">批号/证书编号</th>
                                                                <th style="text-align:center">有效期</th>
                                                                <th style="text-align:center">校准机构</th>
                                                                <th style="text-align:center">计量特性</th>
                                                            </tr>
                                                            <tr>
                                                                <td><input name="BLPH_Xmxh16" type="text" value="/"
                                                                        id="BLPH_Xmxh16" style="height:25px"></td>
                                                                <td><select name="BLPH_Bh17" id="BLPH_Bh17"
                                                                        style="height:30px;width:107px;">
                                                                        <option selected="selected" value="0">==请选择==
                                                                        </option>
                                                                        {% for tool in tools %}
                                                                        <option value="{{ tool.tool_number }}">
                                                                            {{tool.tool_number}}</option>
                                                                        {% endfor %}

                                                                    </select></td>
                                                                <td><input name="BLPH_FW_01" type="text" id="BLPH_FW_01"
                                                                        value="/" style="height:25px;width:60px"></td>
                                                                <td><input name="BLPH_Jlzsbh18" type="text" value="/"
                                                                        id="BLPH_Jlzsbh18" style="height:25px"></td>
                                                                <td><input name="BLPH_Yxrq19" type="text" value="/"
                                                                        id="BLPH_Yxrq19" style="height:25px"></td>
                                                                <td><input name="BLPH_Yzjg20" type="text" value="/"
                                                                        id="BLPH_Yzjg20"
                                                                        style="height:25px;width:100px"></td>
                                                                <td><input name="BLPH_Zqddj21" type="text" value="/"
                                                                        id="BLPH_Zqddj21"
                                                                        style="height:25px; width:140px"></td>

                                                            </tr>
                                                            <tr>
                                                                <td><input name="BLPH_Xmxh22" type="text" value="/"
                                                                        id="BLPH_Xmxh22" style="height:25px"></td>
                                                                <td><select name="BLPH_Bh23" id="BLPH_Bh23"
                                                                        style="height:30px;width:107px;">
                                                                        <option selected="selected" value="/">==请选择==
                                                                        </option>
                                                                        {% for tool in tools %}
                                                                        <option value="{{ tool.tool_number }}">
                                                                            {{tool.tool_number}}</option>
                                                                        {% endfor %}
                                                                    </select></td>
                                                                <td><input name="BLPH_FW_02" type="text" value="/"
                                                                        id="BLPH_FW_02" style="height:25px;width:60px">
                                                                </td>
                                                                <td><input name="BLPH_Jlzsbh24" type="text" value="/"
                                                                        id="BLPH_Jlzsbh24" style="height:25px"></td>
                                                                <td><input name="BLPH_Yxrq25" type="text" value="/"
                                                                        id="BLPH_Yxrq25" style="height:25px"></td>
                                                                <td><input name="BLPH_Yzjg26" type="text" value="/"
                                                                        id="BLPH_Yzjg26"
                                                                        style="height:25px;width:100px"></td>
                                                                <td><input name="BLPH_Zqddj27" type="text" value="/"
                                                                        id="BLPH_Zqddj27"
                                                                        style="width:140px;height:25px">
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td><input name="BLPH_Xmxh28" type="text" value="/"
                                                                        id="BLPH_Xmxh28" style="height:25px"></td>
                                                                <td><select name="BLPH_Bh29" id="BLPH_Bh29"
                                                                        style="height:30px;width:107px;">
                                                                        <option selected="selected" value="0">==请选择==
                                                                        </option>
                                                                        {% for tool in tools %}
                                                                        <option value="{{ tool.tool_number }}">
                                                                            {{tool.tool_number}}</option>
                                                                        {% endfor %}

                                                                    </select></td>

                                                                <td><input name="BLPH_FW_03" type="text" value="/"
                                                                        id="BLPH_FW_03" style="height:25px;width:60px">
                                                                </td>
                                                                <td><input name="BLPH_Jlzsbh30" type="text" value="/"
                                                                        id="BLPH_Jlzsbh30" style="height:25px"></td>
                                                                <td><input name="BLPH_Yxrq31" type="text" value="/"
                                                                        id="BLPH_Yxrq31" style="height:25px"></td>
                                                                <td><input name="BLPH_Yzjg32" type="text" value="/"
                                                                        id="BLPH_Yzjg32"
                                                                        style="height:25px;width:100px"></td>
                                                                <td><input name="BLPH_Zqddj33" type="text" value="/"
                                                                        id="BLPH_Zqddj33"
                                                                        style="width:140px;height:25px">
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td><input name="BLPH_Xmxh34" type="text" value="/"
                                                                        id="BLPH_Xmxh34" style="height:25px"></td>
                                                                <td><input name="BLPH_Bh35" id="BLPH_Bh35" value="/"
                                                                        style="height:30px;width:107px;">

                                                                <td><input name="BLPH_FW_04" type="text" value="/"
                                                                        id="BLPH_FW_04" style="height:25px;width:60px">
                                                                </td>
                                                                <td><input name="BLPH_Jlzsbh36" type="text" value="/"
                                                                        id="BLPH_Jlzsbh36" style="height:25px"></td>
                                                                <td><input name="BLPH_Yxrq37" type="text" value="/"
                                                                        id="BLPH_Yxrq37" style="height:25px"></td>
                                                                <td><input name="BLPH_Yzjg38" type="text" value="/"
                                                                        id="BLPH_Yzjg38"
                                                                        style="height:25px;width:100px"></td>
                                                                <td><input name="BLPH_Zqddj39" type="text" value="/"
                                                                        id="BLPH_Zqddj39"
                                                                        style="width:140px;height:25px">
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td><input name="BLPH_Xmxh40" type="text" value="/"
                                                                        id="BLPH_Xmxh40" style="height:25px"></td>
                                                                <td><input name="BLPH_Bh41" id="BLPH_Bh41" value="/"
                                                                        style="height:30px;width:107px;">

                                                                <td><input name="BLPH_FW_05" type="text" value="/"
                                                                        id="BLPH_FW_05" style="height:25px;width:60px">
                                                                </td>
                                                                <td><input name="BLPH_Jlzsbh42" type="text" value="/"
                                                                        id="BLPH_Jlzsbh42" style="height:25px"></td>
                                                                <td><input name="BLPH_Yxrq43" type="text" value="/"
                                                                        id="BLPH_Yxrq43" style="height:25px"></td>
                                                                <td><input name="BLPH_Yzjg44" type="text" value="/"
                                                                        id="BLPH_Yzjg44"
                                                                        style="height:25px;width:100px"></td>
                                                                <td><input name="BLPH_Zqddj45" type="text" value="/"
                                                                        id="BLPH_Zqddj45"
                                                                        style="width:140px;height:25px">
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td><input name="BLPH_Xmxh46" type="text" value="/"
                                                                        id="BLPH_Xmxh46" style="height:25px"></td>
                                                                <td><input name="BLPH_Bh47" id="BLPH_Bh47" value="/"
                                                                        style="height:30px;width:107px;">

                                                                <td><input name="BLPH_FW_06" type="text" value="/"
                                                                        id="BLPH_FW_06" style="height:25px;width:60px">
                                                                </td>
                                                                <td><input name="BLPH_Jlzsbh48" type="text" value="/"
                                                                        id="BLPH_Jlzsbh48" style="height:25px"></td>
                                                                <td><input name="BLPH_Yxrq49" type="text" value="/"
                                                                        id="BLPH_Yxrq49" style="height:25px"></td>
                                                                <td><input name="BLPH_Yzjg50" type="text" value="/"
                                                                        id="BLPH_Yzjg50"
                                                                        style="height:25px;width:100px"></td>
                                                                <td><input name="BLPH_Zqddj51" type="text" value="/"
                                                                        id="BLPH_Zqddj51"
                                                                        style="width:140px;height:25px">
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>生产厂商</td>
                                                                <td colspan="6"><input name="A1PH_Sccs52" type="text"
                                                                        value="梅特勒托利多" id="A1PH_Sccs52"
                                                                        style="width:900px;height:25px"></td>


                                                            </tr>
                                                            <tr>
                                                                <td>证书单位</td>
                                                                <td colspan="6"><input name="A1PH_Zsdw53" type="text"
                                                                        id="A1PH_Zsdw53"
                                                                        style="width:900px;height:25px"></td>


                                                            </tr>
                                                            <tr>
                                                                <td>证书地址</td>
                                                                <td colspan="6"><input name="A1PH_Zsdz54" type="text"
                                                                        id="A1PH_Zsdz54"
                                                                        style="width:900px;height:25px"></td>


                                                            </tr>
                                                            <tr>
                                                                <td>校准地点</td>
                                                                <td colspan="6"><input name="A1PH_Xzdd55" type="text"
                                                                        id="A1PH_Xzdd55"
                                                                        style="width:900px;height:25px"></td>

                                                            </tr>

                                                        </tbody>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th colspan="6"
                                                    style="height:15px; text-align:left;background-color:aliceblue">
                                                    1. 通用技术要求
                                                </th>
                                            </tr>
                                            <tr>
                                                <th>外观及通电检查：</th>
                                                <td colspan="2">符合 <input id="A1PH_Wgjcfh56" type="checkbox"
                                                        name="A1PH_Wgjcfh56"></td>
                                                <td colspan="3">不符合 <input id="A1PH_Wgjcbfh57" type="checkbox"
                                                        name="A1PH_Wgjcbfh57"></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="c-content-panel">
                        <div class="c-label">2.称量示值误差（g）</div>
                        <div class="c-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <table class="table" id="table1">
                                        <tbody>
                                            <tr>
                                                <th style="vertical-align:middle;width:50px;text-align:center">载荷点</th>
                                                <th style="vertical-align: middle;width:50px;text-align:center">约定质量值
                                                </th>
                                                <th style="vertical-align: middle;width:50px;text-align:center">加载</th>
                                                <th style="vertical-align: middle;width:50px;text-align:center">误差</th>
                                                <th style="vertical-align: middle;width:50px;text-align:center">卸载
                                                </th>
                                                <th style="vertical-align: middle;width:50px;text-align:center">误差<br>
                                                </th>
                                                <th style="vertical-align: middle;width:50px;text-align:center">
                                                    扩展不确定U(<i>k</i>=2)(mg)
                                                </th>

                                            </tr>
                                            <tr>
                                                <td><input name="C1" type="text" id="C1" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px">
                                                </td>
                                                <td><input name="C2" type="number" id="C2" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C3" type="number" id="C3" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C4" type="number" id="C4" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001">
                                                </td>
                                                <td><input name="C5" type="number" id="C5"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C6" type="number" id="C6" onkeyup="Wonkeyup(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C7" type="number" id="C7"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001" readonly>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><input name="C8" type="text" id="C8" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px">
                                                </td>
                                                <td><input name="C9" type="number" id="C9" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C10" type="number" id="C10" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C12" type="number" id="C12" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001">
                                                </td>
                                                <td><input name="C13" type="number" id="C13"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C14" type="number" id="C14" onkeyup="Wonkeyup(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C15" type="number" id="C15"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001" readonly>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><input name="C16" type="text" id="C16" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px">
                                                </td>
                                                <td><input name="C17" type="number" id="C17" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C18" type="number" id="C18" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C19" type="number" id="C19" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001">
                                                </td>
                                                <td><input name="C20" type="number" id="C20"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C21" type="number" id="C21" onkeyup="Wonkeyup(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C22" type="number" id="C22"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001" readonly>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><input name="C23" type="text" id="C23" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px">
                                                </td>
                                                <td><input name="C24" type="number" id="C24" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C25" type="number" id="C25" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C26" type="number" id="C26" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001">
                                                </td>
                                                <td><input name="C27" type="number" id="C27"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C28" type="number" id="C28" onkeyup="Wonkeyup(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C29" type="number" id="C29"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001" readonly>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><input name="C30" type="text" id="C30" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px">
                                                </td>
                                                <td><input name="C31" type="number" id="C31" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C32" type="number" id="C32" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C33" type="number" id="C33" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001">
                                                </td>
                                                <td><input name="C34" type="number" id="C34"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C35" type="number" id="C35" onkeyup="Wonkeyup(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C36" type="number" id="C36"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001" readonly>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><input name="C37" type="text" id="C37" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px">
                                                </td>
                                                <td><input name="C38" type="number" id="C38" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C39" type="number" id="C39" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C40" type="number" id="C40" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001">
                                                </td>
                                                <td><input name="C41" type="number" id="C41"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C42" type="number" id="C42" onkeyup="Wonkeyup(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C43" type="number" id="C43"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001" readonly>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><input name="C44" type="text" id="C44" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px">
                                                </td>
                                                <td><input name="C45" type="number" id="C45" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C46" type="number" id="C46" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="C47" type="number" id="C47" onkeyup="CupperCase6(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001">
                                                </td>
                                                <td><input name="C48" type="number" id="C48"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C49" type="number" id="C49" onkeyup="Wonkeyup(this)"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset;"
                                                        step="0.001">
                                                </td>
                                                <td><input name="C50" type="number" id="C50"
                                                        style="width:100px; height:25px;border-width: 0.5px; border-style: inset; "
                                                        step="0.001" readonly>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="c-content-panel">
                        <div class="c-label">3.称量重复性</div>

                        <div class="c-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <span>请输入测试载荷（g）</span>
                                    <input name="C3" type="text" id="C3" placeholder="请输入" style="margin-bottom: 5px;">

                                    <table class="table table-bordered">
                                        <thead>
                                            <tr>
                                                <th style="vertical-align:middle;text-align:center">1</th>
                                                <th style="vertical-align:middle;text-align:center">2</th>
                                                <th style="vertical-align:middle;text-align:center">3</th>
                                                <th style="vertical-align:middle;text-align:center">4</th>
                                                <th style="vertical-align:middle;text-align:center">5</th>
                                                <th style="vertical-align:middle;text-align:center">6</th>
                                                <th style="vertical-align:middle;text-align:center">7</th>
                                                <th style="vertical-align:middle;text-align:center">8</th>
                                                <th style="vertical-align:middle;text-align:center">9</th>
                                                <th style="vertical-align:middle;text-align:center">10</th>
                                            </tr>

                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td><input name="B1" type="text" id="B1"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="B2" type="text" id="B2"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="B3" type="text" id="B3"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="B4" type="text" id="B4"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="B5" type="text" id="B5"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="B6" type="text" id="B6"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="B7" type="text" id="B7"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="B8" type="text" id="B8"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="B9" type="text" id="B9"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                                <td><input name="B10" type="text" id="B10"
                                                        onchange="SetDigitalInputB(36);"
                                                        style="width:100px; height:25px" step="0.001">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><label style="font-size: 15px;">重复性误差(g)</label></td>
                                                <td>
                                                    <input type="number" id="B11" name="B11" onkeyup="CupperCase(this)"
                                                        onchange="SetDigitalInputB(37);"
                                                        style="width:100px; height:25px" readonly step="0.001"></input>
                                                </td>
                                            </tr>

                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="c-content-panel">
                        <div class="c-label">4.水分测定误差</div>
                        <div class="c-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <table class="table table-hover">
                                        <thead>
                                            <tr>
                                                <th>初始质量值W1(g) </th>
                                                <th>烘干后质量值W2(g)</th>
                                                <th>样品水分测量结果 (%)</th>
                                                <th>水分测定误差(%)</th>
                                                <th>扩展不确定U(<i>k</i>=2)%</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td><input type="text" id="VA1" name="VA1" onkeyup="CupperCase(this)"
                                                        onchange="SetDigitalInputB(37);"
                                                        style="width:150px; height:25px"></input></td>
                                                <td><input type="text" id="VA2" name="VA2" onkeyup="CupperCase(this)"
                                                        onchange="SetDigitalInputB(37);"
                                                        style="width:150px; height:25px"></input></td>
                                                <td><input type="text" id="VA3" name="VA3" onkeyup="CupperCase(this)"
                                                        onchange="SetDigitalInputB(37);"
                                                        style="width:150px; height:25px"></input></td>
                                                <td><input type="text" id="VA4" name="VA4" onkeyup="CupperCase(this)"
                                                        onchange="SetDigitalInputB(37);"
                                                        style="width:150px; height:25px" readonly></input></td>
                                                <td><input type="text" id="VA5" name="VA5" onkeyup="CupperCase(this)"
                                                        onchange="SetDigitalInputB(37);"
                                                        style="width:150px; height:25px"></input></td>

                                            </tr>

                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="c-content-panel">
                        <div class="c-label">5.温度测试（℃）（附加项目）</div>
                        <div class="c-body"> 
                            <div class="row">
                                <div class="col-md-12">
                                    <table class="table table-bordered">
                                        <caption>
                                             设备编号：
                                            <input name="N1" type="text" id="N1"  
                                                style="width:140px; height:25px;border-width: 0.5px; border-style: inset; background-color: #F3F3F3">
                                        </caption>
                                        <caption>
                                             证书编号：
                                            <input name="N2" type="text" id="N2"  
                                                style="width:140px; height:25px;border-width: 0.5px; border-style: inset; background-color: #F3F3F3">
                                        </caption>
                                        <caption>
                                             校准机构：
                                            <input name="N3" type="text" id="N3"  
                                                style="width:140px; height:25px;border-width: 0.5px; border-style: inset; background-color: #F3F3F3">
                                        </caption>
                                        <caption>
                                             有限期限：
                                            <input name="N3" type="text" id="N4"  
                                                style="width:140px; height:25px;border-width: 0.5px; border-style: inset; background-color: #F3F3F3">
                                        </caption>
                                        <tbody>
                                            <tr>
                                                <th>测试点</th>
                                                <th>显示</th>
                                                <th>偏差</th>
                                                <th>允差</th>
                                            </tr>
                                            <tr>
                                                <td><input name="test_point_1" type="text" id="test_point_1" value="100"
                                                        style="width:110px; height:25px;border-width: 0px; font-size:15px; border-style: inset"
                                                        readonly>
                                                </td>
                                                <td><input name="display_1" type="text" id="display_1" value=" "
                                                        style="width:110px; height:25px"
                                                        onkeyup="calculateDeviation(1)">
                                                </td>
                                                <td><input name="deviation_1" type="text" id="deviation_1" value=" "
                                                        style="width:110px; height:25px" readonly>
                                                </td>
                                                <td><input name="tolerance_1" type="text" id="tolerance_1" value="3"
                                                        style="width:110px; height:25px;border-width: 0px; font-size:15px; border-style: inset"
                                                        readonly>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><input name="test_point_2" type="text" id="test_point_2" value="160"
                                                        style="width:110px; height:25px;border-width: 0px; font-size:15px; border-style: inset"
                                                        readonly>
                                                </td>
                                                <td><input name="display_2" type="text" id="display_2" value=" "
                                                        style="width:110px; height:25px"
                                                        onkeyup="calculateDeviation(2)">
                                                </td>
                                                <td><input name="deviation_2" type="text" id="deviation_2" value=" "
                                                        style="width:110px; height:25px" readonly>
                                                </td>
                                                <td><input name="tolerance_2" type="text" id="tolerance_2" value="3"
                                                        style="width:110px; height:25px;border-width: 0px; font-size:15px; border-style: inset"
                                                        readonly>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-bordered">

                            <tbody>
                                <tr>
                                    <th>校准员：</th>
                                    <td><input name="calibrator" type="text" id="calibrator"
                                            style="width:110px; height:25px;border-width: 0.5px; border-style: inset; background-color: #F3F3F3"
                                            value="{{ windows_user }}"></td>
                                    <th>核验员</th>
                                    <td><input name="inspector_Users" type="text" id="inspector_Users"
                                            style="width:110px; height:25px"></td>
                                </tr>
                            </tbody>
                        </table>
                        <div class="S001">
                            <br>
                            <table>
                                <tbody>
                                    <tr>
                                        <td colspan="5" align="center">
                                            <input type="submit" name="Button2" value="提交校准"
                                                onclick="javascript:if(Button2_onclick()==false) return false;"
                                                id="Button2" style="width:80px;">
                                        </td>

                                    </tr>

                                    <tr>
                                        <td colspan="5" align="center">
                                            <a href="/add/" class="btn btn-default btn-xs"
                                                style="margin-top: 10px;width: 80px;">取 消</a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </div>
        </div>
        </div>

    </form>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">

            <div class="modal-body">
                <div class="alert alert-danger alert-dismissible fade in" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                            aria-hidden="true">×</span></button>
                    <h4>注意!</h4>
                    <p>请确认相关数据已经填写正确，提交后无法修改！！！</p>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                        </button>
                        <button type="button" class="btn btn-danger" onclick="confirmAdd();">
                            确定提交
                        </button>
                    </div>
                </div>
            </div>


        </div>
    </div>

</body>


{% endblock %}

{% block js %}
<script src="/static/bootstrap/js/jquery.min.js" type="text/javascript"></script>
<script>
    $(document).ready(function () {
        var data_obj = {{ obj | safe }}

            $.each(data_obj, function (key, value) {
                    var inputSelector = $('input[name="' + key + '"]');
                    if (inputSelector.length) {
                            inputSelector.val(value);
                    }

                    $('select[name="BLPH_Bh17"]').val(data_obj["BLPH_Bh17"]);
                    $('select[name="BLPH_Bh23"]').val(data_obj["BLPH_Bh23"]);
                    $('select[name="BLPH_Bh29"]').val(data_obj["BLPH_Bh29"]);
        });


        // 初始化分度值相关设置（仅处理不确定度字段）
        function initializeUncertaintyValues() {
            // 根据当前分度值设置不确定度
            if ($('#A1PH_d').val() === '0.001') {
                $('#C7, #C15, #C22, #C29, #C36, #C43, #C50').val('4');
                $('#VA5').val('0.09');
            } else {
                $('#C7, #C15, #C22, #C29, #C36, #C43, #C50').val('0.4');
                $('#VA5').val('0.069');
            }
        }
        
        // 页面加载时初始化不确定度值
        initializeUncertaintyValues();

        // 监听分度值选择变化
        $('#A1PH_d').change(function () {
            const decimalPlaces = $(this).val() === '0.001' ? 3 : 4;
            const stepValue = decimalPlaces === 3 ? '0.001' : '0.0001';

            // 保存小数位数到全局变量
            window.currentDecimalPlaces = decimalPlaces;
            window.currentStepValue = stepValue;
            // 扩展不确定
            if ($(this).val() === '0.001') {
                $('#C7, #C15, #C22, #C29, #C36, #C43, #C50').val('4');
                $('#VA5').val('0.09');
            } else {
                $('#C7, #C15, #C22, #C29, #C36, #C43, #C50').val('0.4');
                $('#VA5').val('0.069');
            }

            // 设置所有相关输入框的小数位数和step属性
            $('input[name^="B"], input[name^="C"],input[name^="VA"]').each(function () {
                // 排除固定值字段
                if (this.name.includes('BLPH')) {
                    return;
                }

                // 排除特定的C字段(C1, C8, C16, C23, C30, C37, C44)，这些保持整数
                const excludedFields = ['C1', 'C8', 'C16', 'C23', 'C30', 'C37', 'C44'];
                if (excludedFields.includes(this.name)) {
                    // 对于这些字段，确保值为整数
                    const val = parseFloat($(this).val());
                    if (!isNaN(val)) {
                        $(this).val(Math.round(val));
                    }
                    return;
                }

                // 排除特定字段(C7, C15, C22, C29, C36, C43, C50, VA5)的小数位数限制
                const excludedDecimalFields = ['C7', 'C15', 'C22', 'C29', 'C36', 'C43', 'C50', 'VA5'];
                if (excludedDecimalFields.includes(this.name)) {
                    // 这些字段不进行小数位数格式化
                    return;
                }

                const val = parseFloat($(this).val());
                if (!isNaN(val)) {
                    $(this).val(val.toFixed(decimalPlaces));
                }
                if ($(this).attr('type') === 'number') {
                    $(this).attr('step', stepValue);
                }
            });
        });

        // 初始化小数位数和step
        const initialDecimalPlaces = $('#A1PH_d').val() === '0.001' ? 3 : 4;
        const initialStepValue = initialDecimalPlaces === 3 ? '0.001' : '0.0001';
        window.currentDecimalPlaces = initialDecimalPlaces;
        window.currentStepValue = initialStepValue;

        // 数值输入自动格式化处理
        $('input[name^="B"], input[name^="C"] ,input[name^="VA"]').on('blur', function () {
            // 排除固定值字段
            if (this.name.includes('BLPH')) {
                return;
            }

            // 排除特定的C字段(C1, C8, C16, C23, C30, C37, C44)，这些保持整数
            const excludedFields = ['C1', 'C8', 'C16', 'C23', 'C30', 'C37', 'C44'];
            if (excludedFields.includes(this.name)) {
                // 对于这些字段，确保值为整数
                const val = parseFloat($(this).val());
                if (!isNaN(val)) {
                    $(this).val(Math.round(val));
                }
                return;
            }

            // 排除特定字段(C7, C15, C22, C29, C36, C43, C50, VA5)的小数位数限制
            const excludedDecimalFields = ['C7', 'C15', 'C22', 'C29', 'C36', 'C43', 'C50', 'VA5'];
            if (excludedDecimalFields.includes(this.name)) {
                // 这些字段不进行小数位数格式化
                return;
            }
            
            const val = parseFloat($(this).val());
            if (!isNaN(val)) {
                $(this).val(val.toFixed(window.currentDecimalPlaces));
            }
        });

        // 表格计算逻辑
        $('#table1').on('input', 'input[type="number"]', function () {
            const row = $(this).closest('tr');
            if (row.index() > 0) { // 跳过标题行
                const secondCol = row.find('td:nth-child(2) input').val();
                const thirdCol = row.find('td:nth-child(3) input').val();
                const fivedCol = row.find('td:nth-child(5) input').val();

                if (secondCol && thirdCol) {
                    const result1 = parseFloat(thirdCol) - parseFloat(secondCol);
                    const result2 = parseFloat(fivedCol) - parseFloat(secondCol);
                    row.find('td:nth-child(4) input').val(result1.toFixed(window.currentDecimalPlaces));
                    row.find('td:nth-child(6) input').val(result2.toFixed(window.currentDecimalPlaces));
                }
            }
        });

        // 修改B1-B10计算逻辑
        $('input[name^="B"]').on('input', function () {
            let values = [];
            // 收集B1-B10的值
            for (let i = 1; i <= 10; i++) {
                const val = parseFloat($(`input[name="B${i}"]`).val());
                if (!isNaN(val)) {
                    values.push(val);
                }
            }

            if (values.length > 0) {
                const max = Math.max(...values);
                const min = Math.min(...values);
                const result = max - min;
                $('#B11').val(result.toFixed(window.currentDecimalPlaces));
            }
        });

        // 修改：VA4的值等于VA3输入值减去BLPH_FW_01输入值
        $('input[name^="VA"], #BLPH_FW_01').on('input', function () {
            const va3 = parseFloat($('#VA3').val());
            const blph_fw_01 = parseFloat($('#BLPH_FW_01').val());

            if (!isNaN(va3) && !isNaN(blph_fw_01)) {
                const va4 = va3 - blph_fw_01;
                $('#VA4').val(va4.toFixed(window.currentDecimalPlaces));
            }
        });


        // 温度测试偏差自动计算函数
        window.calculateDeviation = function (index) {
            const testPointValue = parseFloat($(`#test_point_${index}`).val());
            const displayValue = parseFloat($(`#display_${index}`).val());

            if (!isNaN(testPointValue) && !isNaN(displayValue)) {
                const deviation = testPointValue - displayValue;
                $(`#deviation_${index}`).val(deviation.toFixed(1));
            }
        };

        // 监听温度显示值变化
        $('input[id^="display_"]').on('input', function () {
            const id = $(this).attr('id');
            const index = id.split('_')[1];
            calculateDeviation(index);
        });

        $('#tools tr:gt(0)').each(function () {
            $(this).find('td:eq(1) select').change(function () {
                var selectedValue = $(this).val();
                var title = $(this).parent().siblings().eq(0).find('input').first()
                // var range = $(this).parent().siblings().eq(1).find('input').first()
                // var certificate_number = $(this).parent().siblings().eq(2).find('input').first()
                // var end_date = $(this).parent().siblings().eq(3).find('input').first()
                var cal_jigou = $(this).parent().siblings().eq(4).find('input').first()
                var property = $(this).parent().siblings().eq(5).find('input').first()

                $.ajax({
                    type: "GET",
                    url: "/tools/",  // 替换为您的URL
                    dataType: 'JSON',
                    data: {
                        'value': selectedValue,
                    },
                    success: function (data) {
                        // 假设返回的数据填充到input
                        var n = data.datalist;
                        title.val(n[0].fields.title);
                        // range.val(n[0].fields.range);
                        // certificate_number.val(n[0].fields.certificate_number);
                        // end_date.val(n[0].fields.end_date);
                        cal_jigou.val(n[0].fields.cal_jigou);
                        property.val(n[0].fields.property);
                    }
                });
            });
        });
    });
</script>

{% endblock %}